package cn.e3mall.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import cn.e3mall.common.pojo.EasyUITreeNode;
import cn.e3mall.mapper.TbItemCatMapper;
import cn.e3mall.pojo.TbItemCat;
import cn.e3mall.pojo.TbItemCatExample;
import cn.e3mall.pojo.TbItemCatExample.Criteria;
import cn.e3mall.service.ItemCatService;

@Service
public class ItemCatServiceImpl implements ItemCatService {

	@Autowired
	private TbItemCatMapper itemCatMapper;
	
	@Override
	public List<EasyUITreeNode> getItemCatlist(long parentId) {
		TbItemCatExample example = new TbItemCatExample();
		Criteria Criteria = example.createCriteria();
		Criteria.andParentIdEqualTo(parentId);
		List<TbItemCat> list= itemCatMapper.selectByExample(example);
		List<EasyUITreeNode> resultlist=new ArrayList<EasyUITreeNode>();
		for (TbItemCat t : list) {
			EasyUITreeNode node = new EasyUITreeNode();
			node.setId(t.getId());
			node.setText(t.getName());
			node.setState(t.getIsParent()?"closed":"open");
			resultlist.add(node);
		}
		return resultlist;
		
	}

}
